package com.lzb.randomturntable.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.lzb.randomturntable.AppConfig;
import com.lzb.randomturntable.BaseAc;
import com.lzb.randomturntable.R;
import com.lzb.randomturntable.bean.FeedbackBean;
import com.lzb.randomturntable.databinding.ActivityFeedbackBinding;
import com.lzb.randomturntable.utils.OkHttpPostUtil;

public class FeedbackActivity extends BaseAc<ActivityFeedbackBinding> implements View.OnClickListener {

    private FeedbackBean feedbackBean = new FeedbackBean();

    @Override
    protected int onCreate() {
        return R.layout.activity_feedback;
    }

    @Override
    protected void initView() {
        mDataBinding.ivFeedbackBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        mDataBinding.tvCommit.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tvCommit) {//提交
            String content = mDataBinding.etContent.getText().toString().trim();
            if (TextUtils.isEmpty(content)) {
                ToastUtils.showShort(getString(R.string.please_input_feedback));
                return;
            }
            feedbackBean.setContent(content);
            OkHttpPostUtil.getInstance().postJson(AppConfig.FEEDBACK_DATA, new Gson().toJson(feedbackBean), new OkHttpPostUtil.HttpCallback() {
                @Override
                public void onSuccess(String response) {
                    ToastUtils.showShort(getString(R.string.commit_suc));
                    finish();
                }

                @Override
                public void onFailure(String error) {
                    ToastUtils.showShort(getString(R.string.commit_error));
                }
            });
        }
    }

    @Override
    protected void initData() {

    }
}